// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {

    },
    init(gamectl){
        this.gamectl = gamectl;
        this.getComponent(cc.RigidBody).linearVelocity = cc.v2(0,0);
        cc.log('init hotdog');
    },
    onBeginContatct:function(contact,selfCollider,otherCollider){
        this.gamectl.onBallContactWall(selfCollider.node,otherCollider.node);
    },
    turn:function (Xp,Yp) {
        let p = this.node.parent.convertToNodeSpace(cc.v2(Xp,Yp));
        cc.log(p.x,p.y)
        let r = this.angle(this.node.position,p);
        cc.log(r);
        this.node.rotation = 90-r;
        let rt = (r/360)*Math.PI*2;
        this.getComponent(cc.RigidBody).linearVelocity = cc.v2(Math.cos(rt)*1400,Math.sin(rt)*1400);
    },
    angle:function(start,end) {
        var diff_x = end.x - start.x,
            diff_y = end.y - start.y;
        //返回角度,不是弧度
        return 360 * Math.atan(diff_y / diff_x) / (2 * Math.PI);
    },
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    //start () {

    //},

    // update (dt) {},
});
